package com.lyc.demo.complex;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ComplexTest {
    public static void main(String[] args) {
        List<Complex> list = new ArrayList<>();
        Random random = new Random();
        //向集合添加50个Complex对象
        for (int i = 0; i < 50; i++) {
            list.add(new Complex(random.nextInt(1000), random.nextInt(1000)));
        }


        //然后我们将集合中imag大于200和real值大于400的对象筛选打印输出


        //首先要定义一个匿名内部类来实现ComplexChecker接口中的check（）方法
//        ComplexChecker checker = new ComplexChecker() {
//
//            @Override
//            public boolean check(Complex c) {
//                return c.imag > 200 && c.real > 400;
//            }
//        };
//
//        show(list, checker);

        show(list, c -> c.imag > 200 && c.real > 400);

    }

    public static void show(List<Complex> lists, ComplexChecker checker) {
        for (Complex com : lists) {
            if (checker.check(com))
                System.out.println(com);
        }
    }

}
